package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;

/**
 * 课外活动记录实体类
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "id")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "extracurricular_recordings", indexes = {
        @Index(name = "idx_recording_date", columnList = "activity_date"),
        @Index(name = "idx_recording_teacher", columnList = "teacher_id"),
        @Index(name = "idx_recording_class", columnList = "class_id")
})
public class ExtracurricularRecording {

    /**
     * 记录ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 教师ID
     */
    @NotNull(message = "教师ID不能为空")
    @Column(name = "teacher_id", nullable = false)
    private Integer teacherId;

    /**
     * 学期ID
     */
    @NotNull(message = "学期ID不能为空")
    @Column(name = "term_id", nullable = false)
    private Integer termId;

    /**
     * 班级IDcasterName = "class_id", nullable = false)
     private Integer classId;

     /**
     * 活动标题
     */


    @NotNull(message = "班级ID不能为空")
    @Column(name = "class_id", nullable = false)
    private Integer classId;  // 🔧 这里应该是 classId



    @NotBlank(message = "活动标题不能为空")
    @Size(max = 200, message = "活动标题长度不能超过200个字符")
    @Column(nullable = false)
    private String title;

    /**
     * 活动描述
     */
    @Size(max = 2000, message = "活动描述长度不能超过2000个字符")
    @Column(columnDefinition = "TEXT")
    private String description;

    /**
     * 活动分类
     */
    @NotBlank(message = "活动分类不能为空")
    @Size(max = 50, message = "活动分类长度不能超过50个字符")
    @Column(nullable = false)
    private String category;

    /**
     * 活动日期
     */
    @NotNull(message = "活动日期不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Column(name = "activity_date", nullable = false)
    private LocalDate activityDate;

    /**
     * 开始时间
     */
    @NotNull(message = "开始时间不能为空")
    @JsonFormat(pattern = "HH:mm:ss")
    @Column(name = "start_time", nullable = false)
    private LocalTime startTime;

    /**
     * 结束时间
     */
    @NotNull(message = "结束时间不能为空")
    @JsonFormat(pattern = "HH:mm:ss")
    @Column(name = "end_time", nullable = false)
    private LocalTime endTime;

    /**
     * 总时长（分钟）
     */
    @Column(name = "total_minutes")
    private Integer totalMinutes;

    /**
     * 缩略图URL
     */
    @Size(max = 255, message = "缩略图URL长度不能超过255个字符")
    @Column(name = "thumbnail_url")
    private String thumbnailUrl;

    /**
     * 视频URL
     */
    @NotBlank(message = "视频URL不能为空")
    @Size(max = 255, message = "视频URL长度不能超过255个字符")
    @Column(name = "video_url", nullable = false)
    private String videoUrl;

    /**
     * 文档URL
     */
    @Size(max = 255, message = "文档URL长度不能超过255个字符")
    @Column(name = "document_url")
    private String documentUrl;

    /**
     * 相册URL
     */
    @Size(max = 255, message = "相册URL长度不能超过255个字符")
    @Column(name = "photo_album_url")
    private String photoAlbumUrl;

    /**
     * 活动类型
     */
    @Size(max = 50, message = "活动类型长度不能超过50个字符")
    @Column(name = "activity_type")
    private String activityType;

    /**
     * 活动地点
     */
    @Size(max = 100, message = "活动地点长度不能超过100个字符")
    private String location;

    /**
     * 参与人数
     */
    @Column(name = "participant_count")
    private Integer participantCount;

    /**
     * 成果描述
     */
    @Size(max = 2000, message = "成果描述长度不能超过2000个字符")
    @Column(name = "achievement_description", columnDefinition = "TEXT")
    private String achievementDescription;

    /**
     * 获奖信息
     */
    @Size(max = 500, message = "获奖信息长度不能超过500个字符")
    @Column(name = "award_info")
    private String awardInfo;

    /**
     * 学生作品URL
     */
    @Size(max = 255, message = "学生作品URL长度不能超过255个字符")
    @Column(name = "student_works_url")
    private String studentWorksUrl;

    /**
     * 是否发布
     */
    @NotNull(message = "发布状态不能为空")
    @Column(name = "is_published")
    @Builder.Default
    private Boolean isPublished = true;

    /**
     * 是否推荐
     */
    @NotNull(message = "推荐状态不能为空")
    @Column(name = "is_featured")
    @Builder.Default
    private Boolean isFeatured = false;

    /**
     * 审批状态
     */
    @Size(max = 20, message = "审批状态长度不能超过20个字符")
    @Column(name = "approval_status")
    @Builder.Default
    private String approvalStatus = "pending";

    /**
     * 查看次数
     */
    @Column(name = "view_count")
    @Builder.Default
    private Integer viewCount = 0;

    /**
     * 点赞次数
     */
    @Column(name = "like_count")
    @Builder.Default
    private Integer likeCount = 0;

    /**
     * 分享次数
     */
    @Column(name = "share_count")
    @Builder.Default
    private Integer shareCount = 0;

    /**
     * 创建人ID
     */
    @NotNull(message = "创建人ID不能为空")
    @Column(name = "created_by", nullable = false)
    private Integer createdBy;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by")
    private Integer updatedBy;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;
}
